﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using LayeredArchitectureSample.DataAccess;
using LayeredArchitectureSample.Services;

namespace LayeredArchitectureSample.ServiceHosts
{
    class Program
    {
        static void Main(string[] args)
        {
            var serviceHosts = new List<ServiceHost>();

            var remoteWareRepository =
                new RemoteWareRepository(
                    new EntityFrameworkWareRepository(
                        new DatabaseContextFactory()));

            serviceHosts.Add(new ServiceHost(remoteWareRepository));

            var locationRepository = new EntityFrameworkLocationRepository(
                new DatabaseContextFactory());

            var remoteLocationRepository =
                new RemoteLocationRepository(
                    locationRepository);

            serviceHosts.Add(new ServiceHost(remoteLocationRepository));

            var remoteRouteRepository =
                new RemoteRouteRepository(
                    new EntityFrameworkRouteRepository(new DatabaseContextFactory()));

            serviceHosts.Add(new ServiceHost(remoteRouteRepository));

            var tripManager =
                new TripManager(
                    new EntityFrameworkTripRepository(new DatabaseContextFactory(), new TripStateMapper()));

            serviceHosts.Add(new ServiceHost(tripManager));

            foreach (ServiceHost serviceHost in serviceHosts)
            {
                serviceHost.Open();
            }

            Console.WriteLine(Resources.HitEnterToStopServices);

            Console.ReadLine();

            foreach (ServiceHost serviceHost in serviceHosts)
            {
                serviceHost.Close();
            }
        }
    }
}